
***************************************************************************************
* Replication code for: "The Cost of Debating Harassment against Politicians: Are Women and Men Affected Equally?"
* Michal Grahn & Sandra Håkansson (2025)

* INSTALL PACKAGES
* ssc install coefplot
* ssc install estout
* net install grc1leg2.pkg, from (http://digital.cgdev.org/doc/stata/MO/Misc/)
* ssc install matmap
* ssc install mat2txt
* ssc install conjoint
* ssc install asdoc

* LOAD DATA 
use "Grahn Håkansson POBE 2025.dta", clear

* Figure 1A
conjoint chosen woman_dummy_profile foreign_dummy_profile age_group_profile education_profile private_dummy_profile incumbent_dummy_profile exp_profile leader_dummy_profile performance_profile loyal_profile media_profile2, estimate(mm) id(id)
matrix all_mm=e(results)

coefplot (matrix(all_mm[,1]), ci((all_mm[,5] all_mm[,6])) keep(*:)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) msize(medlarge) ciopts(lcolor(black)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) eqlabels("{bf:Gender}" "{bf:Immigrant background}" "{bf:Age group}" "{bf:Education}" "{bf:Works within private sector}" "{bf:Incumbent}" "{bf:Political experience}" "{bf:Leadership experience}" "{bf:Performance track-record}" "{bf:Loyalty}" "{bf:Media engagement}", asheadings gap(1)) coeflabels(Male="Man" Female="Woman" _1="Yes" _0="No" No="No" Yes="Yes" Male="Male" Female="Female" Native="No" Foreign="Yes" _18_34="18-34" _35_65="35-65" _65_="65+" No_higher_education="No higher education" Bachelor_degree="Bachelor's degree'" Masters__degree_="Masters' degree" _5_months="5 months" _1_year="1 year" _4_years="4 years" _8_years="8 years" _12_years="12 years" _17_years="17 years" Worse_than_expected="Worse than expected" As_expected="As expected" Better_than_expected="Better than expected" Disloyal="Disloyal" Somewhat_loyal="Somewhat loyal" Very_loyal="Very loyal" Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Transport_and_communications="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.5)  xtitle("Marginal mean")  title(, color(black)) aspect(1) xla(0.3(0.1)0.7)

* Figure 1B
conjoint chosen media_profile, estimate(mm) id(id)
matrix media_profile_results_mm=e(results)

coefplot (matrix(media_profile_results_mm[,1]), ci((media_profile_results_mm[,5] media_profile_results_mm[,6])) keep(*:)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.7) xtitle("Marginal mean") title(, color(black) span) subtitle(, color(black) span) aspect(1)

* Figure 2
conjoint chosen media_profile if woman_dummy_profile==1, estimate(mm) id(id)
matrix media_profile_women_mm=e(results)

conjoint chosen media_profile if woman_dummy_profile==0, estimate(mm) id(id)
matrix media_profile_men_mm=e(results)

coefplot (matrix(media_profile_women_mm[,1]), ci((media_profile_women_mm[,5] media_profile_women_mm[,6])) keep(*:) offset(0.1) label("Women candidates") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(media_profile_men_mm[,1]), ci((media_profile_men_mm[,5] media_profile_men_mm[,6])) keep(*:) offset(-0.1) label("Men candidates") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(gray)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.7)  xtitle("Marginal mean")  title(, color(black) span) subtitle(, color(black) span) aspect(1) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A2
conjoint chosen media_profile if resp_party_left==1, estimate(mm) id(id)
matrix media_profile_left_mm=e(results) 

conjoint chosen media_profile if resp_party_left==0, estimate(mm) id(id)
matrix media_profile_right_mm=e(results)

coefplot (matrix(media_profile_left_mm[,1]), ci((media_profile_left_mm[,5] media_profile_left_mm[,6])) keep(*:) offset(0.1) label("Left respondents""(MP & V)") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(media_profile_right_mm[,1]), ci((media_profile_right_mm[,5] media_profile_right_mm[,6])) keep(*:) offset(-0.1) label("Right respondents""(KD, L, M, & SD)") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(gray)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.7)  xtitle("Marginal mean") title(, color(black) span) subtitle(, color(black) span) aspect(1) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A3
conjoint chosen media_profile if resp_male_dummy==0, estimate(mm) id(id)
matrix media_profile_resp_women_mm=e(results)

conjoint chosen media_profile if resp_male_dummy==1, estimate(mm) id(id)
matrix media_profile_resp_men_mm=e(results)

coefplot (matrix(media_profile_resp_women_mm[,1]), ci((media_profile_resp_women_mm[,5] media_profile_resp_women_mm[,6])) keep(*:) offset(0.1) label("Women respondents") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(media_profile_resp_men_mm[,1]), ci((media_profile_resp_men_mm[,5] media_profile_resp_men_mm[,6])) keep(*:) offset(-0.1) label("Men respondents") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(gray)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.7)  xtitle("Marginal mean") title(, color(black) span) subtitle(, color(black) span) aspect(1) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A4
conjoint chosen media_profile if inlist(resp_municipality_size, 1, 2), estimate(mm) id(id)
matrix media_profile_small_mm=e(results)

conjoint chosen media_profile if inlist(resp_municipality_size, 2, 3), estimate(mm) id(id)
matrix media_profile_large_mm=e(results)

coefplot (matrix(media_profile_small_mm[,1]), ci((media_profile_small_mm[,5] media_profile_small_mm[,6])) keep(*:) offset(0.1) label("Respondents from small""municipalities (<50,000)") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(media_profile_large_mm[,1]), ci((media_profile_large_mm[,5] media_profile_large_mm[,6])) keep(*:) offset(-0.1) label("Respondents from large""municipalities (>50,000)") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(gray)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.9)  xtitle("Marginal mean")  title(, color(black) span) subtitle(, color(black) span) aspect(1) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A5
conjoint chosen media_profile if choice_pair_B1==1, estimate(mm) id(id)
matrix media_profile_B1_results_mm=e(results)

conjoint chosen media_profile if choice_pair_B2==1, estimate(mm) id(id)
matrix media_profile_B2_results_mm=e(results)

noisily conjoint chosen media_profile if choice_pair_B3==1, estimate(mm) id(id)
matrix media_profile_B3_results_mm=e(results)

noisily conjoint chosen media_profile if choice_pair_B4==1, estimate(mm) id(id)
matrix media_profile_B4_results_mm=e(results)

conjoint chosen media_profile if choice_pair_B5==1, estimate(mm) id(id)
matrix media_profile_B5_results_mm=e(results)

* Figure A6
conjoint chosen media_profile2, estimate(amce) id(id)
matrix media_profile_results_amce=e(results)
asdoc wmat, mat(media_profile_results_amce) save(Sandra/Tabeller/media_profile_all_amce.rtf) replace

coefplot (matrix(media_profile_results_amce[,1]), ci((media_profile_results_amce[,5] media_profile_results_amce[,6])) keep(*:)), ///
    xline(0, lpattern(-) lcolor(black)) ///
    mcolor(black) ciopts(lcolor(black)) ///
    graphregion(color(white) margin(zero)) ///
    xla(-0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2) /// specify exact ticks
    coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" ///
    School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" ///
    Rarely_engages_with_media="Rarely") ///
    scale(0.7) xtitle("AMCE") ///
    title(, color(black) span) subtitle(, color(black) span) aspect(1)

* Figure A7
conjoint chosen media_profile2 if woman_dummy_profile==1, estimate(amce) id(id)
matrix media_profile_women_amce=e(results)

conjoint chosen media_profile2 if woman_dummy_profile==0, estimate(amce) id(id)
matrix media_profile_men_amce=e(results)

coefplot (matrix(media_profile_women_amce[,1]), ci((media_profile_women_amce[,5] media_profile_women_amce[,6])) keep(*:) offset(0.1) label("Women candidates") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(media_profile_men_amce[,1]), ci((media_profile_men_amce[,5] media_profile_men_amce[,6])) keep(*:) offset(-0.1) label("Men candidates") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(gray)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.7)  xtitle("AMCE")  title(, color(black) span) subtitle(, color(black) span) aspect(1) xla(-0.05(0.05)0.2) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A8
conjoint chosen issue_visibility2, estimate(mm) id(id)
matrix issue_visibility_results_mm=e(results)

coefplot (matrix(issue_visibility_results_mm[,1]), ci((issue_visibility_results_mm[,5] issue_visibility_results_mm[,6])) keep(*:)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) graphregion(color(white) margin(zero)) coeflabels(No_visibility="Rarely" Harassment="Harassment" Non_salient="Non-salient" Salient="Salient") scale(1) xtitle("Marginal mean") title(, color(black) span) subtitle(, color(black) span) aspect(1)

conjoint chosen issue_visibility2, estimate(amce) id(id)
matrix issue_visibility_results_amce=e(results)

coefplot (matrix(issue_visibility_results_amce[,1]), ci((issue_visibility_results_amce[,5] issue_visibility_results_amce[,6])) keep(*:)), xline(0, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) graphregion(color(white) margin(zero)) xla(-0.05(0.05)0.2) coeflabels(No_visibility="Rarely" Harassment="Harassment" Non_salient="Non-salient" Salient="Salient") scale(1) xtitle("AMCE") title(, color(black) span) subtitle(, color(black) span) aspect(1)

* Figure A9
conjoint chosen issue_visibility2 if woman_dummy_profile==1, estimate(mm) id(id)
matrix issue_visibility_women_mm=e(results)

conjoint chosen issue_visibility2 if woman_dummy_profile==0, estimate(mm) id(id)
matrix issue_visibility_men_mm=e(results)

coefplot (matrix(issue_visibility_women_mm[,1]), ci((issue_visibility_women_mm[,5] issue_visibility_women_mm[,6])) keep(*:) offset(0.1) label("Women candidates") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(issue_visibility_men_mm[,1]), ci((issue_visibility_men_mm[,5] issue_visibility_men_mm[,6])) keep(*:) offset(-0.1) label("Men candidates") mcolor(black) ciopts(lcolor(black)) msymbol(S)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels(No_visibility="Rarely" Harassment="Harassment" Non_salient="Non-salient" Salient="Salient") scale(1)  xtitle("Marginal mean")  title(, color(black) span) subtitle(, color(black) span) aspect(0.8) legend(region(color(none)) row(1) keygap(1) pos(6))

* Figure A10
conjoint chosen woman_dummy_profile foreign_dummy_profile age_group_profile education_profile private_dummy_profile exp_profile leader_dummy_profile performance_profile loyal_profile media_profile if incumbent_dummy_profile==1, estimate(mm) id(id)
matrix incumbent_mm=e(results)

conjoint chosen woman_dummy_profile foreign_dummy_profile age_group_profile education_profile private_dummy_profile exp_profile leader_dummy_profile performance_profile loyal_profile media_profile if incumbent_dummy_profile==0, estimate(mm) id(id)
matrix nonincumbent_mm=e(results)

coefplot (matrix(incumbent_mm[,1]), ci((incumbent_mm[,5] incumbent_mm[,6])) keep(*:) offset(0.2) label("Incumbent candidates") mcolor(black) ciopts(lcolor(black)) msymbol(Oh)) (matrix(nonincumbent_mm[,1]), ci((nonincumbent_mm[,5] nonincumbent_mm[,6])) keep(*:) offset(-0.2) label("Non-incumbent candidates") mcolor(black) ciopts(lcolor(black))), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) eqlabels( "{bf:Gender}" "{bf:Immigrant background}" "{bf:Age group}" "{bf:Education}" "{bf:Works within private sector}" "{bf:Political experience}" "{bf:Leadership experience}" "{bf:Performance track-record}" "{bf:Loyalty}" "{bf:Media engagement}", asheadings gap(1)) coeflabels(_1="Yes" _0="No" No="No" Yes="Yes" Male="Male" Female="Female" Native="No" Foreign="Yes" Productive_age="Productive age" Low_Education="Low education" Middle_Education="Middle education" High_Education="High education" _5_months="5 months" _1_year="1 year" _4_year="4 years" _8_years="8 years" _12_years="12 years" _17_years="17 years" Worse_than_expected="Worse than expected" As_expected="As expected" Better_than_expected="Better than expected" Disloyal="Disloyal" Somewhat_loyal="Somewhat loyal" Very_loyal="Very loyal" Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.5)  xtitle("Marginal mean")  title(, color(black)) aspect(1.5) xla(0.3(0.1)0.7) legend(region(color(none)) row(1) keygap(1) pos(6) colgap(0.17cm))

* Figure A11
conjoint chosen media_profile if performance_profile==1, estimate(mm) id(id)
matrix performance_1_mm=e(results)
conjoint chosen media_profile if performance_profile==2, estimate(mm) id(id)
matrix performance_2_mm=e(results)
conjoint chosen media_profile if performance_profile==3, estimate(mm) id(id)
matrix performance_3_mm=e(results)

coefplot (matrix(performance_1_mm[,1]), ci((performance_1_mm[,5] performance_1_mm[,6])) keep(*:) offset(0.1) label("Worse than expected") mcolor(black) ciopts(lcolor(black)) msymbol(O)) (matrix(performance_2_mm[,1]), ci((performance_2_mm[,5] performance_2_mm[,6])) keep(*:) offset(-0.1) label("As expected") mcolor(black) ciopts(lcolor(black)) msymbol(Oh)) (matrix(performance_3_mm[,1]), ci((performance_3_mm[,5] performance_3_mm[,6])) keep(*:) offset(-0.3) label("Better than expected") mcolor(black) ciopts(lcolor(black)) msymbol(Th)), xline(0.5, lpattern(-) lcolor(black)) mcolor(black) ciopts(lcolor(black)) grid(glcolor(gs14)) graphregion(color(white) margin(zero)) coeflabels( Democracy_issues="Democracy" Threats_against_politicians="Harassment" School_issues="Education" Trafic="Transport and communications" Welfare_issues="Welfare" Rarely_engages_with_media="Rarely") scale(0.5)  xtitle("Marginal mean")  title(, color(black)) aspect(1.5) xla(0.3(0.1)0.7) legend(region(color(none)) row(1) keygap(1) pos(6) colgap(0.17cm))
